<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
  <%@page import="java.util.*"%>
  <%@page import="java.sql.*, support.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Applications</title>
</head>
<body>
	<%String action = request.getParameter("action");%>
	<%
	if(action.equals( "specialization")) { 
		String specid = request.getParameter("specid"); 
		String specname = request.getParameter("specname");
	%>
		Applications of specialization - <%= specname %>
	<p>
		<table border="1">
			<%
			Connection conn = null;
			try {
				conn = DBUtils.getConnection();
				Statement stmt = conn.createStatement();
				ResultSet rset=
					stmt.executeQuery("SELECT * FROM name JOIN maintable ON name.nameid = maintable.nameid where specid = '" + specid + "'");
				// Print out the specialization and the number of applications
				while (rset.next()){
			%>
				<tr>
				<td  width="100"><%=rset.getString("first") %> <%=rset.getString("middle") %> <%=rset.getString("last") %></td>
				</tr>
				<%
				}
				rset.close();
				stmt.close();
			
			}
			catch (ServiceException e) {
				throw e;
			} catch (Exception e) {
				DBUtils.rollback(conn);
				throw new ServiceException("error occur inquiring applications");
			} finally {
				DBUtils.closeConnection(conn);
			}
			%>
		</table>
	<%}
	if(action.equals("discipline")){
		String majorid = request.getParameter("majorid"); 
		String majorname = request.getParameter("majorname");
	%>
		Applications of discipline: <%= majorname %>
	
		<table border="1">
			<%
			Connection conn = null;
			try {
				conn = DBUtils.getConnection();
				Statement stmt = conn.createStatement();
				ResultSet rset=
					stmt.executeQuery("SELECT * FROM name, maintable, degree WHERE name.nameid = maintable.nameid AND maintable.tableid = degree.tableid AND degree.major = '" + majorid + "'");
				// Print out the specialization and the number of applications
				while (rset.next()){
			%>
				<tr>
				<td  width="100"><%=rset.getString("first") %> <%=rset.getString("middle") %> <%=rset.getString("last") %></td>
				</tr>
				<%
				}
				rset.close();
				stmt.close();
			
			}
			catch (ServiceException e) {
				throw e;
			} catch (Exception e) {
				DBUtils.rollback(conn);
				throw new ServiceException("error occur inquiring applications");
			} finally {
				DBUtils.closeConnection(conn);
			}
		%>
		</table>
	<%} %>
</body>
</html>